var JSONxEdit_jsonTree_defaultRootNode = new Ext.tree.TreeNode({
	text: 'JSON',
	value: '|||JSON|ROOT|NODE|||',
	draggable:false,
	leaf: false,
	id:'json_tree_root_node',
	iconCls: "ico_object",
	type: "object",
	expanded: true
});

var JSONxEdit_jsonTree = new Ext.tree.TreePanel({
	id: 'JSONxEdit_TreePanel',
	region: 'west',
	collapsible: false,
	width: 200,
	autoScroll: true,
	split: true,
	enableDD: true,
	loader: new Ext.tree.TreeLoader(),
	selModel: new Ext.tree.DefaultSelectionModel({
		listeners: {
			'beforeselect': function (sel, n, o) {
				if (n.attributes.id == "json_tree_root_node")
				{
					disableEditor();
				}
				else
				{
					if ( n.attributes.leaf == false ) {
						JSONxEdit_jsonEditorForm.disable();

						if (JSONxEdit_jsonEditorTabPanel.activeTab < 2)
							JSONxEdit_jsonEditorTabPanel.setActiveTab(1);

						JSONxEdit_jsonEditorObjectForm.enable();
						JSONxEdit_jsonEditorObjectForm.setVisible(true);

						Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_index").setValue( n.attributes.text );
						Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_indexId").setValue( n.attributes.id );
						Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_index").enable();
						if ( n.parentNode != null )
						{
							if (n.parentNode.attributes.type == "array")
							{
								Ext.getCmp("JSONxEdit_FormPanel_editorObjectForm_index").disable();
							}
						}
					} else {
						JSONxEdit_jsonEditorObjectForm.disable();

						if (JSONxEdit_jsonEditorTabPanel.activeTab < 2)
							JSONxEdit_jsonEditorTabPanel.setActiveTab(0);

						JSONxEdit_jsonEditorForm.enable();
						JSONxEdit_jsonEditorForm.setVisible(true);

						Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").setValue( n.attributes.text );
						Ext.getCmp("JSONxEdit_FormPanel_editorForm_value").setValue( n.attributes.value );
						Ext.getCmp("JSONxEdit_FormPanel_editorForm_isNull").setValue( ( n.attributes.type == "null" ));
						Ext.getCmp("JSONxEdit_FormPanel_editorForm_keyId").setValue( n.attributes.id );

						Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").enable();
						if ( n.parentNode != null )
						{
							if (n.parentNode.attributes.type == "array")
							{
								Ext.getCmp("JSONxEdit_FormPanel_editorForm_key").disable();
							}
						}
					}
				}
			}
		}
	}),
	root: JSONxEdit_jsonTree_defaultRootNode,
	rootVisible: true,
	tbar: JSONxEdit_jsonTree_toolbar,
	listeners: {
		'disable': function() {
			setTreeDefaultRootNode();

			Ext.getCmp("icon_tree_addKey").setIconClass("icon_tree_addKey_disabled");
			Ext.getCmp("icon_tree_delete").setIconClass("icon_tree_delete_disabled");
		},
		'enable': function() {
			Ext.getCmp("icon_tree_addKey").setIconClass("icon_tree_addKey");
			Ext.getCmp("icon_tree_delete").setIconClass("icon_tree_delete");
		},
		'beforeappend': function (tree, parent, node) {
			debug.trace("hmm");
			
		}
	}
});